package com.ushine.web.template.mybatis.controller;

import com.ushine.web.component.http.HttpResponseVO;
import com.ushine.web.log.annotation.SystemControllerLog;
import com.ushine.web.log.constant.LogConstant;
import com.ushine.web.template.mybatis.model.DemoDO;
import com.ushine.web.template.mybatis.service.IDemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yls
 * @Date 2022/2/7 16:19
 * @Description: mybatis plus查询测试
 * @Version 1.0
 **/
@RestController
@RequestMapping("component/mybatis")
@Api(tags = "组件模块-mybatis集成测试")
public class DemoController {

    @Resource
    private IDemoService demoService;

    @SystemControllerLog(operation = LogConstant.READ)
    @ApiOperation(value = "根据id查询")
    @GetMapping("get/{id}")
    public HttpResponseVO<DemoDO> getDemoById(@PathVariable Long id) {
        DemoDO demo = demoService.getDemoById(id);
        return new HttpResponseVO<DemoDO>().ok("", demo);
    }

    @SystemControllerLog(operation = LogConstant.READ)
    @ApiOperation(value = "查询列表数据")
    @GetMapping("listDemos/{username}")
    public HttpResponseVO<List<DemoDO>> listDemos(@PathVariable String username) {
        List<DemoDO> demos = demoService.listDemos(username);
        return new HttpResponseVO<List<DemoDO>>().ok("", demos);
    }
}
